package com.kawaiior.asoulworld.items.weapon;

import com.kawaiior.asoulworld.capability.AsoulTimePower;
import com.kawaiior.asoulworld.capability.CapabilityRegistryHandler;
import com.kawaiior.asoulworld.items.AsWeaponBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;


public class ItemTimeSword extends AsWeaponBase {

    public ItemTimeSword(String name) {
        super(name);
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 10;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        if (worldIn.isRemote) return super.onItemRightClick(worldIn, playerIn, handIn);

        AsoulTimePower power = playerIn.getCapability(CapabilityRegistryHandler.ASOUL_TIME_POWER, null);
        if (power != null && !power.isHot()){

            int[] pos = power.getTime();

            if (pos != null && pos.length == 3){
                int h = power.getPlayerHealth() > playerIn.getHealth() ? power.getPlayerHealth() : (int)(playerIn.getHealth()+1f);
                playerIn.setHealth(h);
                playerIn.setPositionAndUpdate(pos[0], pos[1], pos[2]);

//                worldIn.createExplosion(playerIn, pos[0], pos[1]+2, pos[2], 2, false);

                power.setHot();
            }

            playerIn.getCooldownTracker().setCooldown(this, 1200);
        }

        return super.onItemRightClick(worldIn, playerIn, handIn);
    }
}
